//
//  DataBaseTool.m
//  dongfengTest
//
//  Created by wxt on 2021/3/29.
//

#import "DataBaseTool.h"

@implementation DataBaseTool
+(FMDatabase *)openDataBase{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"user.sqlist"];
    FMDatabase *dataBase = [FMDatabase databaseWithPath:path];
    BOOL isSuccess = [dataBase open];
    if (isSuccess == YES) {
        ZRLog(@"打开数据库成功");
        return dataBase;
    }else{
        ZRLog(@"打开数据库失败");
        return nil;
    }
}

+(void)openDataBaseAndCreateUserTable{
    FMDatabase *dataBase = [self openDataBase];
    // id,user_id,mobile,nickname,avatar
    BOOL isSuccess = [dataBase executeUpdate:@"create table if not exists user(userName text , passWord text )"];
    if (!isSuccess) {
        NSLog(@"创建表成功");
    }else{
//        NSLog(@"创建表失败");
        // 这里写的是not an error但是添加数据是成功的
        // 并且也能查询到数据，所以这里not an error暂时判断表是创建成功了
        NSLog(@"创建表error = %@", [dataBase lastErrorMessage]);
    }
    [dataBase close];
}
+(void)openDataBaseAndCreateUserPINTable{
    FMDatabase *dataBase = [self openDataBase];
    // id,user_id,mobile,nickname,avatar
    BOOL isSuccess = [dataBase executeUpdate:@"create table if not exists userCer(userName text , payWord text )"];
    if (!isSuccess) {
        NSLog(@"创建证书表成功");
    }else{
//        NSLog(@"创建表失败");
        // 这里写的是not an error但是添加数据是成功的
        // 并且也能查询到数据，所以这里not an error暂时判断表是创建成功了
        NSLog(@"创建证书表error = %@", [dataBase lastErrorMessage]);
    }
    [dataBase close];
}
@end
